package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.Comment;
import com.cskaoyan.bean.CommentCountVO;
import com.cskaoyan.bean.WxCommentQuery;
import com.cskaoyan.bean.comment.CommentListVO;
import com.cskaoyan.service.WxCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("wx/comment")
public class WxCommentController {

    @Autowired
    WxCommentService wxCommentService;

    @GetMapping("list")
    public BaseRespVo commentList(@RequestParam(value = "valueId") Integer valueId,@RequestParam(value = "type") Byte type,
                                  @RequestParam(value = "showType") Integer showType,@RequestParam(value = "page")Integer page,
                                  @RequestParam(value = "limit") Integer limit) {
        WxCommentQuery wxCommentQuery=new WxCommentQuery();
        wxCommentQuery.setValueId(valueId);
        wxCommentQuery.setType(type);
        wxCommentQuery.setShowType(showType);
        wxCommentQuery.setPage(page);
        wxCommentQuery.setLimit(limit);
        CommentListVO commentListVO = wxCommentService.list(wxCommentQuery);
        return BaseRespVo.ok(commentListVO);
    }

    @GetMapping("count")
    public BaseRespVo commentCount(@RequestParam(value = "valueId") Integer valueId,@RequestParam(value = "type")Byte type) {
        WxCommentQuery wxCommentQuery=new WxCommentQuery();
        wxCommentQuery.setValueId(valueId);
        wxCommentQuery.setType(type);
        CommentCountVO commentCountVO=wxCommentService.count(wxCommentQuery);
        return BaseRespVo.ok(commentCountVO);
    }

    @RequestMapping("post")
    public BaseRespVo commentCount(@RequestBody Comment comment) {
        Integer res = wxCommentService.post(comment);
        if (res == 1) {
            return BaseRespVo.ok(null);
        } else {
            return BaseRespVo.invalidData();
        }
    }
}
